﻿using System;
using System.Collections.Generic;
using ACompany.OrderProcessing.Infrastructure;
using ACompany.OrderProcessing.Model;

namespace ACompany.OrderProcessing.Model
{
    public class Customer : BusinessBase<Customer>, IAggregateRoot
    {
        #region Fields
        private Address _address;
        private string _name;
        private string _email;
        private IList<Order> _orders;

        #endregion

        protected override void Validate()
        {
            if (this.Address == null)
                this.BrokenRules.Add(new BrokenRule("Address", "A Customer must have an address"));

            if (String.IsNullOrEmpty(this.Email))
                this.BrokenRules.Add(new BrokenRule("Email", "Email is a required value"));
            else if (this.Email.Length > 50)
                this.BrokenRules.Add(new BrokenRule("Email", "Email should be 50 chars or less"));

            if (String.IsNullOrEmpty(this.Name))
                this.BrokenRules.Add(new BrokenRule("Name", "Name is a required value"));
            else if (this.Name.Length > 50)
                this.BrokenRules.Add(new BrokenRule("Name", "Name should be 50 chars or less"));
        }

        public Address Address
        {
            get { return _address; }
            set { _address = value; }
        }

        public string Name
        {
            get { return _name; }
            set { _name = value; }
        }

        public string Email
        {
            get { return _email; }
            set { _email = value; }
        }

        public IList<Order> Orders
        {
            get { return _orders; }
            //set { _orders = value; }
        }

    }
}
